<template>
  <MainContent title="触达限制">
    <div>
      <el-button @click="setReachCondition" type="primary">{{ isDisabled ? '编辑' : '保存' }}</el-button>
    </div>

    <div>
      <div v-for="(item, index) in dataList.rules" :key="index">
            <div class="rc-header"><span class="rc-img"></span><span class="rc-title">{{titleList[item.reachType].name}}</span></div>
            <div class="rc-content">
              <el-radio-group v-model="item.disable" :disabled="isDisabled">
                <el-radio :label="1">限制（如下）</el-radio>
                <el-radio :label="0">不限制</el-radio>
              </el-radio-group>

              <div v-if="item.disable == 1">
                <span>每人每天最多接受</span>
                <el-input-number
                  v-model="item.dayCount"
                  :min="1"
                  :max="10"
                  controls-position="right"
                  size="large"
                />
                <span>条{{titleList[item.reachType].label}}，</span>
                <span>每小时最多接收</span>
                <el-input-number
                  v-model="item.hourCount"
                  :min="1"
                  :max="10"
                  controls-position="right"
                  size="large"
                />
                <span>条{{titleList[item.reachType].label}}</span>
              </div>
            </div>
            
      </div>

    </div>
  </MainContent>
</template>

<script lang="ts" setup>
import reachPipelineApi from "@/api/reachPipelineApi";
const isDisabled = ref(true)
//     sms(1, SendMsgReachReqBody.class,"短信"),
//     aiCall(2, SendAiCallReachReqBody.class,"ai外呼"),
//     email(3, SendMailReachReqBody.class,"邮件"),
//     publicWx(4, SendPublicWxReachReqBody.class,"公众号消息"),
//     workWx(5, SendWorkWxReachReqBody.class,"企微消息"),
//     rpaProcess(6,SendRpaReachReqBody.class,"Rpa加好友"),
//     unKnow(-1,SendMailReachReqBody.class,"未知");
const titleList = reactive({
    1: {
      name: '短信',
      icon: '',
      label: '短信',
    },
    3: {
      name: '邮件',
      icon: '',
      label: '邮件',
    },
    4: {
      name: '公众号通知',
      icon: '',
      label: '公众号通知',
    },
})
const dataList = reactive({
  rules: [
  {
    reachType: 1,
    dayCount: 1,
    hourCount: 1,
    disable: 0,
  },
  {
    reachType: 3,
    dayCount: 1,
    hourCount: 1,
    disable: 0,
  },
  {

    reachType: 4,
    dayCount: 1,
    hourCount: 1,
    disable: 0,
  },
]
})
const getReachCondition = async () => {
  let rs = await reachPipelineApi.getReachCondition()
  if (rs.code === 200 && rs.payload.length) {
    console.log('rs-get',rs);
    dataList.rules = rs.payload
  }
}

const setReachCondition = async () => {
  if(!isDisabled.value) {
    // 如果不限制则初始化数值
    dataList.rules.forEach(item=>{
      if(item.disable == 0) {
        item.dayCount = 1
        item.hourCount = 1
      }
    })

    let rs = await reachPipelineApi.setReachCondition({rules: dataList.rules})
    if (rs.code === 200) {
      console.log('rs-set', rs);
      ElMessage.success('触达限制设置成功')
    }
  }
  isDisabled.value = !isDisabled.value
}

onBeforeMount(() => {
  getReachCondition() //获取限制配置
})
</script>

<style lang="scss" scoped>
</style>